﻿document.addEventListener('DOMContentLoaded', function () {
    // 获取会话超时时间（从配置中获取）
    const timeoutMinutes = 15; // 默认15分钟
    const timeoutMs = timeoutMinutes * 60 * 1000;

    // 最后活动时间
    let lastActivity = new Date().getTime();

    // 定时检查活动状态
    setInterval(checkActivity, 1000);

    // 页面交互事件监听
    document.addEventListener('mousemove', resetActivityTimer);
    document.addEventListener('keypress', resetActivityTimer);
    document.addEventListener('click', resetActivityTimer);
    document.addEventListener('scroll', resetActivityTimer);
    document.addEventListener('touchmove', resetActivityTimer);

    function checkActivity() {
        const currentTime = new Date().getTime();
        const elapsedTime = currentTime - lastActivity;

        if (elapsedTime > timeoutMs) {
            // 超时，重定向到登出
            window.location.href = '/Account/Logout';
        }
    }

    function resetActivityTimer() {
        lastActivity = new Date().getTime();
    }
});